﻿using Entitas;
/// <summary>
/// when the mouse is pressed the hitbox for the current equipped weapon for the player will be instantiated 
/// </summary>
class PlayerAttackSystem : IExecuteSystem
{
    readonly PlayerContext Playercontext;
    public PlayerAttackSystem(Contexts context)
    {
        Playercontext = context.player;
    }
    public void Execute()
    {
        if (Playercontext.count == 1)
        {
            var player = Playercontext.GetEntities().SingleEntity<PlayerEntity>();


            if (!player.isAttacking && player.hasEquippedWeapon)
            {
                if (ServiceManager.InputService.MousePressed)
                {

                    //flag to know that player has just attacked
                    // instantiate hitbox with weapon name, Positon of weapon user,  the name ofweapon user, and 
                    //the direction the hitbox needs to instanted(Left,right,up,down)
                    ServiceManager.ViewService.InstantiateHitBox(player.equippedWeapon.value, player.position.value,
                        player.name.value, player.direction.value);
                    //depending on the equipped weapon their may be different cool down times.

                    if (!player.hasAttackTimer)
                    {
                        player.AddAttackTimer(player.equippedWeapon.value.AttackTime);
                    }
                    else player.ReplaceAttackTimer(player.equippedWeapon.value.AttackTime);

                }
            }
        }
    }
}
